<?php
/* ================================================================================
 * Template Base Class 
 *
 * TemplateBase.php: This class is used to drive the template system.
 *
 * Author: Eric Hendrickson (enhendrickson@liberty.edu)
 * Date: 8/26/2005
   ================================================================================ */


include_once('ContentBase.php');

class TemplateBase
{
	var $title;
	var $sectionSkipFlags;
	var $menu;
	var $menuTitle;
	var $menuNum;
	var $templateFilePath; 

	function __construct($templateFilePath=null) {
		if($templateFilePath!=null) {
			$this->templateFilePath = $templateFilePath;
		}
		return $this;
	}
		
	public function printTemplate($dataBean=null) {
		ob_start();	
		$templateFilePath = $_SERVER['DOCUMENT_ROOT'] .'/'. $this->templateFilePath;

		//load the file contents 
		$fileContents = file_get_contents($templateFilePath);		
		//calculate the template root
		$templateRoot = substr($this->templateFilePath,0,strrpos($this->templateFilePath,"\\"));
		if(trim($templateRoot) == "") {
			$templateRoot = substr($this->templateFilePath,0,strrpos($this->templateFilePath,"/"));
			$templateRoot = $templateRoot . "/";
		}
		else {
			$templateRoot = $templateRoot . "\\";
		}
		$fileContents = str_replace("{TEMPLATE_ROOT}",$templateRoot,$fileContents);
		
		//let the derrived classes replace what they need to			
		$fileContents = $this->replaceTemplateVariables($fileContents, $dataBean);
		
		//print the contents after all of the template variables have been replaced
		print $fileContents;
		ob_end_flush();
	}
	
	public function replaceTemplateVariables($fileContents, $dataBean=null) {
		//override this function if you want to make sure that the appropriate template
		//variables can be replated with text at runtime
		return $fileContents;
	}
}
?>
